<template>
    <div>
        <el-table
            ref="tableOfMemberGroup"
            :data="memberGroupData"
            border
            header-cell-class-name="main-table-header"
            @selection-change="onSelectionChange"
            @row-click="onRowClick"
        >
            <el-table-column type="selection" width="39"></el-table-column>
            <el-table-column align="center" label="标题">
                <template slot-scope="{ row }">
                    {{ row.rfmType | formatRFMType }}
                </template>
            </el-table-column>
            <el-table-column align="center" label="数量" prop="count" />
        </el-table>
        <el-row type="flex" justify="center" style="margin-top:30px">
            <el-button type="primary" icon="el-icon-check" @click="onConfirm"
                >确认</el-button
            >
            <el-button type="default" icon="el-icon-close" @click="onCancel"
                >取消</el-button
            >
        </el-row>
    </div>
</template>

<script>
import { get } from "@/assets/js/http.js";

export default {
    name: "select-member-group",
    data() {
        return {
            memberGroupData: [],
            memberGroupSelection: []
        };
    },
    filters: {
        formatRFMType(rfmType) {
            if (rfmType === 0) {
                return "沉睡客户";
            } else if (rfmType === 1) {
                return "体验客户";
            } else if (rfmType === 2) {
                return "需刺激客户";
            } else if (rfmType === 3) {
                return "潜力客户";
            } else if (rfmType === 4) {
                return "重要挽留客户";
            } else if (rfmType === 5) {
                return "重要发展客户";
            } else if (rfmType === 6) {
                return "重要唤回客户";
            } else if (rfmType === 7) {
                return "高价值客户";
            }
        }
    },
    mounted() {
        this.getMemberGroupData();
    },
    methods: {
        async getMemberGroupData() {
            const data = await get({
                url: "/admin/user.RealmeritUser/userRfmStatistics",
                loading: true,
                params: {}
            });
            this.memberGroupData = data.row;
        },
        onConfirm() {
            this.$emit("select-member-group", this.memberGroupSelection);
            this.$parent.$emit("update:visible", false);
            this.$refs.tableOfMemberGroup.clearSelection();
        },
        onCancel() {
            this.$parent.$emit("update:visible", false);
            this.$refs.tableOfMemberGroup.clearSelection();
        },
        onSelectionChange(memberGroupSelection) {
            this.memberGroupSelection = memberGroupSelection;
        },
        onRowClick(row) {
            this.$refs.tableOfMemberGroup.toggleRowSelection(row);
        }
    }
};
</script>